(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

(* A |builder 'a| can be used to create a |list 'a| by successively appending
   elements to the end of the list. *)
type 'a builder

(* |make ()| creates a new list builder. O(1) *)
val make : unit -> 'a builder
  
(* |is_empty <b>| checks whether the current list is still empty.
   O(1), pure *)
val is_empty : 'a builder -> bool
  
(* |clear <b>| empties the builder. O(1), non-pure *)
val clear : 'a builder -> unit
  
(* |add <b> <x>| adds the element <x> at the end of the current list.
   |add_first <b> <x>| adds <x> to the front. O(1), non-pure *)
val add : 'a builder -> 'a -> unit
  
val add_first : 'a builder -> 'a -> unit
  
(* |add_list <b> <x>| adds all elements of the list <x> to the end of the current
   list. O(x), non-pure *)
val add_list : 'a builder -> 'a list -> unit
  
(* |append <b1> <b2>| appends the contents of <b2> to <b1> and resets <b2>.
   O(1), non-pure *)
val append : 'a builder -> 'a builder -> unit
  
(* |get <b>| returns the current list and resets the builder. O(1), non-pure *)
val get : 'a builder -> 'a list
  
(* |get_last <b>| returns the last element of the current list. O(1), pure *)
val get_last : 'a builder -> 'a
  
(* |replace_last <b> <x>| replaces the last element of the current list with <x>. *)
val replace_last : 'a builder -> 'a -> unit
  

